package com.dataworker.spark.sql;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.util.Date;

/**
 * @author melin 2021/7/1 11:09 下午
 */
public class HdfsDemo {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path("/user/hive/warehouse/bigdata.db/tdl_ftp_demo");
        displayDirectoryContents(fs, path);
        fs.close();
    }

    private static void displayDirectoryContents(FileSystem fs, Path rootDir) {
        // TODO Auto-generated method stub
        try {
            System.out.println(new Date(fs.getFileStatus(rootDir).getModificationTime()).toString());
            System.out.println(new Date(fs.getFileStatus(rootDir).getAccessTime()).toString());

            FileStatus[] status = fs.listStatus(rootDir);
            for (FileStatus file : status) {
                System.out.println("FILE : " + file.getPath() + " - Last modification time : " + new Date(file.getModificationTime()).toString());
                System.out.println("FILE : " + file.getPath() + " - Last access time : " + new Date(file.getAccessTime()).toString());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
